﻿/* $RCSFile: ConfigurationPanel.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.Core/UI/WebControls/ConfigurationPanel.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:29  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

using AddonNice.Diagnostics;
using AddonNice.Settings;

using Trace2    =   System.Diagnostics.Trace;

namespace AddonNice.UI.WebControls
{
	public enum ConfiguratorPanelOrientation
	{
		Horizontal,
		Vertical
	}

	public class ConfiguratorPanel : Panel, IPostBackDataHandler
	{
        protected override void OnPreRender(EventArgs e)
        {
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ConfiguratorPanel OnPreRender BEG IsPostBack: {0}, Visible: {1}", Page.IsPostBack,Visible), WebControlsTraceSwitch.Sw.Info);
            string gPath    =   Path.ToAbsolute(Config.PortalScriptsPath + "/ConfigurationPanel.js");
            ((ADNPage)Page).RegisterADNClientScriptInclude(GetType(),"ConfigurationPanel",gPath);
            base.OnPreRender(e);
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine("[V]ConfiguratorPanel OnPreRender END.", WebControlsTraceSwitch.Sw.Info);
        }
		protected override void RenderContents(HtmlTextWriter writer)
		{
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine("[V]ConfiguratorPanel RenderContents BEG.",WebControlsTraceSwitch.Sw.Info);
			writer.Write(string.Format(
				@"<div class=""adnPnlConfig{4}"">
				<a class=""adnCfgPnlHead adnPnlClear"" href=""javascript:slideConfig('{0}', '{1}');"" onfocus=""blur()"">
                    <span class=""adnCfgPnlTitle"">{2}</span>
					<span class=""adnCfgPnlButton adnCfgPnl{1}""></span>
                </a>
                <div class=""adnCfgPnlContent adnPnlClear"" style=""{3}"">",
				/*UniqueID*/ClientID,
				Expanded ? "Up" : "Down",
				Title,
				Expanded ? "" : "display:none",
				Orientation == ConfiguratorPanelOrientation.Vertical ? " adnCfgPnlVertical" : "")
			);

			base.RenderContents(writer);

			writer.Write(string.Format(@"<input type=""hidden"" name=""{0}"" value=""{1}"" /></div></div>",
				/*UniqueID*/ClientID,
				Expanded)
				);
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine("[V]ConfiguratorPanel RenderContents END.",WebControlsTraceSwitch.Sw.Info);
		}

		[DefaultValue("Configuration")]
		public string Title
		{
			get { return (string)(ViewState["Title"] ?? "Configuration"); }
			set { ViewState["Title"] = value; }
		}

		[DefaultValue(false)]
		public bool Expanded
		{
			get { return (bool)(ViewState["Expanded"] ?? false); }
			set { ViewState["Expanded"] = value; }
		}

		[DefaultValue(ConfiguratorPanelOrientation.Horizontal)]
		public ConfiguratorPanelOrientation Orientation
		{
			get { return (ConfiguratorPanelOrientation)(ViewState["Orientation"] ?? ConfiguratorPanelOrientation.Horizontal); }
			set { ViewState["Orientation"] = value; }
		}

		public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
		{
			if (!string.IsNullOrEmpty(postCollection[postDataKey]))
			{
				Expanded = Convert.ToBoolean(postCollection[postDataKey]);
			}
			return true;
		}

		public void RaisePostDataChangedEvent()
		{
		}
	}
}